﻿using System;
using System.Collections.Generic;
using System.Text;
using EnvDTE;
using EnvDTE80;

namespace RunVistaGadget31
{
    class DTECommandCreator
    {
        private DTE2 ApplicationObject;
        private AddIn AddInInstance;

        static object[] ContextGUIDS = new object[] { };
        static int CommandIndex = 0;

        public DTECommandCreator(DTE2 applicationObject, AddIn addInInstance)
        {
            ApplicationObject = applicationObject;
            AddInInstance = addInInstance;
        }

        public Command CreateDTECommand(string commandName, string buttonText, string tooltip, int bitmapNumber)
        {
            Command NewCommand = null;
            try
            {
                NewCommand = ApplicationObject.Commands.Item(AddInInstance.ProgID + "." + commandName, DTECommandCreator.CommandIndex);
            }
            catch
            {

            }

            // Add the command if it does not exist
            if (NewCommand == null)
            {
                NewCommand = ApplicationObject.Commands.AddNamedCommand(AddInInstance, commandName, buttonText, tooltip, true, bitmapNumber, ref DTECommandCreator.ContextGUIDS, (int)vsCommandStatus.vsCommandStatusSupported + (int)vsCommandStatus.vsCommandStatusEnabled);
                DTECommandCreator.CommandIndex += 1;
            }

            return NewCommand;
        }

    }
}
